<?php
defined('BASEPATH') OR exit('No direct script access allowed');
	class login_model extends CI_Model{
        public $table_name='user_admin';
   	    public function get_one_login($username,$password){
            $data=array(
                'username'=>$username,
                'password'=>$password
            );
            $query=$this->db->where($data)->get($this->table_name);
            return $query->row();
        }
        public function get_username_check($username){
            $query=$this->db->where('username',$username)->get($this->table_name);
            return $query->result();
        }
        public function get_add_username($username,$password){
            $time=time();
            $data=array(
                'id'=>null,
                'username'=>$username,
                'password'=>$password,
                'create_time'=>$time
            );
            $this->db->insert($this->table_name, $data);
        }
        public function add_cart($user_id,$product_id,$num){
            $this->db->insert('user_cart',array(
                'user_id'=>$user_id,
                'product_id'=>$product_id,
                'num'=>$num
            ));
        }
        public function get_one_cart($user_id,$product_id){
            $query= $this->db->where(array(
                'user_id'=>$user_id,
                'product_id'=>$product_id
            ))->get('user_cart');
            return $query->row();
        }
        public function update_cart($user_id,$product_id,$num){
            $this->db->query("update user_cart set num=num+$num where user_id=$user_id and product_id=$product_id");
        }
        public function cart_count($user_id){
            $query=$this->db->where('user_id',$user_id)->get('user_cart');
            return count($query->result());
        }
        public function get_all_user_cart(){
            $query=$this->db->get('user_cart');
            return $query->result();
        }
        public function get_one_carts($id,$user_cata){
            $query=$this->db->where(array(
                'product_id'=>$id,
                'user_id'=>$user_cata
                ))->get('user_cart');
            return $query->row();
        }
        public function get_all_cata_id($user_id){
            $query=$this->db->where('user_id',$user_id)->get('user_cart');
            return $query->result();
        }
        public function delete_one_cart($id){
            $this->db->where('id',$id)->delete('user_cart');
        }
        public function cartdels($ids){
            $this->db->where_in('id',$ids)->delete('user_cart');
        }
        public function update_cart_num($id,$num){
            $this->db->where('id',$id)->update('user_cart',array('num'=>$num));
        }
	}